package com.esjob.task;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.dataflow.DataflowJob;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: LCG
 * 作者: LCG
 * 日期: 2021/3/19  10:21
 * 描述:
 */
@Component
public class MyDataFlowTask implements DataflowJob<Map<String,Object>> {



    /**
     * 作者: LCG
     * 日期: 2021/3/19  10:41
     * 描述: 获取数据
     * @Param [shardingContext]
     * @Return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
     */
    @Override
    public List<Map<String, Object>> fetchData(ShardingContext shardingContext) {
        List<Map<String,Object>> list=new ArrayList<>();
        Map<String,Object> map=new HashMap<>();
        map.put("zhangsan","123");
        list.add(map);


        return list;
    }

    /**
     * 作者: LCG
     * 日期: 2021/3/19  10:41
     * 描述: 处理数据
     * @Param [shardingContext, list]
     * @Return void
     */
    @Override
    public void processData(ShardingContext shardingContext, List<Map<String, Object>> list) {

        for (Map<String, Object> map : list) {
            System.out.println("========>"+map);
        }

        try {
            Thread.sleep(1000L);

        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}
